
public class ThreadDemo11{
    public static void main(String[] args){
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t1 = new Thread(()->{
            while(true){
                synchronized(lock1){
                    System.out.println("t1-lock1");
                    try{
                        Thread.sleep(1000);
          }catch(InterruptedException e){
                        e.printStackTrace();
          }
                    synchronized(lock2){
                        System.out.println("t1-lock1-lock2");
                    }

                }
            }
        });


        Thread t2 = new Thread(()->{
            while(true){
                synchronized(lock2){
                    System.out.println("t2-lock2");
                    try{
                        Thread.sleep(1000);
          }catch(InterruptedException e){
                        e.printStackTrace();
          }
                    synchronized(lock1){
                        System.out.println("t2-lock2-lock1");
          }
        }
      }
    });
        t1.start();
        t2.start();
    }
}
